package com.orhon.smartcampus.modules.teacher.dao;

import com.orhon.smartcampus.basicComponents.baseDao.BaseDaoImpl;
import com.orhon.smartcampus.modules.base.entity.Grades;
import com.orhon.smartcampus.modules.systemctl.entity.Menus;
import com.orhon.smartcampus.modules.teacher.entity.TeacherAndPeriods;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Component;

import javax.transaction.Transactional;
import java.util.List;

@Component
public class TeacherAndPeriodsDao extends BaseDaoImpl<TeacherAndPeriods> {


    @Transactional
    public void insert(TeacherAndPeriods entity){
        Session session =this.getSession();
        session.save(entity);
    }
    @Transactional
    public void update(TeacherAndPeriods entity){
        Long teacher_id=entity.getId();
        Session session = this.getSession();
        StringBuffer sb = new StringBuffer("update base_teacher_periods_relation  set period_id= :period_id where teacher_id= :teacher_id");
        String hql = "update TeacherAndPeriods where teacher_id = :teacher_id";
        Query query = session.createSQLQuery(sb.toString()).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).setParameter("teacher_id",teacher_id);
        session.update(entity);

    }
    @Transactional
    public List<Grades> GradesList(Long teacher_id){
        Session session = this.getSession();
        StringBuffer sb = new StringBuffer("select * from base_teacher_periods_relation where teacher_id= :teacher_id");
        Query query = session.createSQLQuery(sb.toString()).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).setParameter("teacher_id",teacher_id);
        return  query.list();
    }






}
